package javabase.schoolwork.day6_10;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author fance
 * @date 2018/6/10 14:44
 */
public class ExecutorDemo {
    public static void main(String[] args) {
        ExecutorService service =
                Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
            final int count = i;
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()  +
                            ":" + count);

                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
            service.submit(runnable);
        }
        service.shutdown();
    }
}
